Package com.apps.outgoing

Source Code of com.apps.outgoing.EmailNotifier

/*
* AUTHOR: Kevin Lam
*/


package com.apps.outgoing;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailNotifier {

  private static Properties p = new Properties();
  private static Session s = Session.getDefaultInstance(p, null);

  public EmailNotifier() {
   
   
  }

  public static boolean sendMessage(String recipient, String body) {

    try {
      Message msg = new MimeMessage(s);
      msg.setFrom(new InternetAddress("noreply@ubc-cc.appspotmail.com",
          "UBC Course Companion"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
          recipient, recipient));
      msg.setSubject("UBC Course Information Update Notification");
      msg.setText(body);
      Transport.send(msg);

    } catch (AddressException e1) {
      e1.printStackTrace();
      return false;
    } catch (MessagingException e2) {
      e2.printStackTrace();
      return false;
    } catch (UnsupportedEncodingException e3) {
      e3.printStackTrace();
      return false;
    }
    return true;
  }
}
TOP

Related Classes of com.apps.outgoing.EmailNotifier

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.